import {
  PageResult,
  DisableRes,
  TonOrderGroup,
  putTonOrderGroupDto,
  TonOrderGroupGateway,
  deleteTonOrderGroupDto,
  TonOrderGroupInterfaceWithPrimary,
  PutMutiRes,
} from "qqlx-core";

import { ViewBase, ViewBaseAction } from "../view-base";
import { TonOrderGroupSchema } from "@/river/ton-order";

export class ViewTonOrderGroup extends ViewBase<TonOrderGroup> implements ViewBaseAction<TonOrderGroup>, TonOrderGroupInterfaceWithPrimary<{}> {
  private static instance: ViewTonOrderGroup;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewTonOrderGroup();
    }

    if (!this.instance) this.instance = new ViewTonOrderGroup();
    return this.instance;
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }

  getSchema(): TonOrderGroup {
    return new TonOrderGroupSchema();
  }

  async get() {
    this.pending();
    return this.$request.get<null, PageResult<TonOrderGroup>>(TonOrderGroupGateway.path);
  }

  async putSync() {
    this.pending();
    const dto = { schemaList: this.data.schemaList };
    return this.$request.put<putTonOrderGroupDto, PutMutiRes<TonOrderGroup>>(TonOrderGroupGateway.path, dto);
  }

  async disable(dto: deleteTonOrderGroupDto) {
    this.pending();
    return this.$request.delete<deleteTonOrderGroupDto, DisableRes>(TonOrderGroupGateway.path, dto);
  }
}
